package com.enzoism.springboot.dive.foreach;

import com.enzoism.springboot.dive.model.UsrModel;

import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

public class A01MapForEach {
    public static void main(String[] args) {
        List<UsrModel> usrList = UsrModel.initList();
        Map<String, List<UsrModel>> listMap = usrList.stream().collect(Collectors.groupingBy(UsrModel::getUsrId));

        // 场景一：map进行快速遍历ForEachStream
        map进行快速遍历ForEachStream(listMap);

        // 场景二：map进行快速遍历
        map进行快速遍历Entry(listMap);

        // 场景三：map进行快速遍历Iterator
        map进行快速遍历Iterator(listMap);
    }

    private static void map进行快速遍历ForEachStream(Map<String, List<UsrModel>> listMap) {
        listMap.forEach((key, value) -> {
            System.out.println("----->key:" + key + "----value:" + value);
        });
    }

    private static void map进行快速遍历Entry(Map<String, List<UsrModel>> listMap) {
        for (Map.Entry<String, List<UsrModel>> stringListEntry : listMap.entrySet()) {
            System.out.println(stringListEntry.getKey() + "--->" + stringListEntry.getValue());
        }
    }

    private static void map进行快速遍历Iterator(Map<String, List<UsrModel>> listMap) {
        Iterator<Map.Entry<String, List<UsrModel>>> iterator = listMap.entrySet().iterator();
        while (iterator.hasNext()) {
            Map.Entry<String, List<UsrModel>> next = iterator.next();
            System.out.println(next.getKey() + "--->" + next.getValue());
        }
    }


}
